package cn.hfatec.shms.web.vip.vipXzb.action;

import cn.hfatec.shms.cache.CodeInfoCache;
import cn.hfatec.shms.enums.CodeType;
import cn.hfatec.shms.web.members.customer.model.CustomerParams;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.Arrays;
import javax.annotation.Resource;


import cn.hfatec.JsonResponse;
import cn.hfatec.Page;
import cn.hfatec.Table;
import cn.hfatec.constants.SysContant;
import cn.hfatec.freemarker.FreeMarkerUtil;
import cn.hfatec.shms.web.vip.vipXzb.model.VipXzbParams;
import cn.hfatec.shms.web.vip.vipXzb.model.VipXzb;
import cn.hfatec.shms.web.vip.vipXzb.service.VipXzbService;
import cn.hfatec.shms.base.ShmsBaseAction;
import org.springframework.ui.Model;

import javax.validation.Valid;

import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;


/**
 * @author hfatec codegen
 * @version 1.0
 *          <p/>
 *          the JAVA code is generate by middlegen
 */
@Controller
@RequestMapping("/vip/vipXzb")
public class VipXzbAction extends ShmsBaseAction {

    //服务层
    @Resource(name = "VipXzbService")
    private VipXzbService vipXzbService;


    /**
     * 查询列表
     */
    @RequestMapping("/list")
    public String list(VipXzbParams vipXzbParams, Page page, Model model) {

          Table table = vipXzbService.queryVipXzbTable(vipXzbParams, page);
             model.addAttribute("vipXzbsTable", table);
        model.addAttribute("vipXzbParams", vipXzbParams);
        return "/vip/vipXzb/list";
    }

    /**
     * 异步查询列表
     */
    @RequestMapping("/ajaxList")
    @ResponseBody
    public String ajaxList(VipXzbParams vipXzbParams, Page page, Model model) {
        try {
            list(vipXzbParams, page, model);
            return new JsonResponse<Map>(JsonResponse.RETURN_SUCCESS, "", FreeMarkerUtil.render("/vip/vipXzb/table", model)).toString();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return JsonResponse.error;
    }

    /**
     * 跳转到选择卡别页
     */
    @RequestMapping("/dorefreshVip")
    @ResponseBody
    public String dorefreshVip(VipXzbParams vipXzbParams, Page page, Model model) {

        try {
            list(vipXzbParams, page, model);
            return new JsonResponse<Map>(JsonResponse.RETURN_SUCCESS, "", FreeMarkerUtil.render("/vip/vipXzb/selectVip", model)).toString();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return JsonResponse.error;
    }

    /**
     * 异步查询列表
     */
    @RequestMapping("/ajaxSelectList")
    @ResponseBody
    public String ajaxSelectList(VipXzbParams vipXzbParams, Model model, Page page) {
        try {
            list(vipXzbParams, page, model);
            model.addAttribute("vipXzbParams", vipXzbParams);
               return new JsonResponse<Map>(JsonResponse.RETURN_SUCCESS, "", FreeMarkerUtil.render("/vip/vipXzb/selectTable", model)).toString();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return JsonResponse.error;
    }
}
